package com.speedydial;

import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;

import com.speedydial.persistence.MessageDbAdapter;

/**
 * Por ahora solo practicando el Activity
 * 
 * @author mario
 *
 */
public class Main extends Activity {

	
	private MessageDbAdapter mDbHelper;
	
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.message_list);
        
        // setting the database routines
        mDbHelper = new MessageDbAdapter(this);
        mDbHelper.open();
        
        final ListView contacts = (ListView) 
        				 findViewById(R.id.contact);
        
        contacts.setAdapter(new ArrayAdapter<String>(
                this,
                R.layout.contact_item,
                getResources().getStringArray(R.array.contacts)));
        
        // por ahora comentamos la creacion de la base de datos
        //data();
        mDbHelper.close();
    }
    
    @Override
    protected void onResume() {
    	super.onResume();
    }
  
    @Override
    protected void onStop() {
    	super.onStop();
    } 

    private void data() {
        // Get all of the notes from the database and create the item list
        Cursor c = mDbHelper.fetchAllNotes();
        startManagingCursor(c);

        String[] from = new String[] { MessageDbAdapter.KEY_TITLE };
        int[] to = new int[] { R.id.message };
        
        // Now create an array adapter and set it to display using our row
        SimpleCursorAdapter notes = new SimpleCursorAdapter(this, R.layout.list_item, c, from, to);
        
        // TODO: descomentar al momento de cambiar a ListActivity
        //setListAdapter(notes);
    }
}
